let fs = require("fs")
// 读取当前目录下有哪些文件
let readDir = fs.readdirSync("./")
// 过滤出目录下除了readme.md外的markdown文件
let markdownFileList = readDir.filter(item => {
    let temFileName = item.toLocaleLowerCase()
    return temFileName.endsWith(".md") && !temFileName.startsWith("readme")
})
// 构建readme.md文件内容
let markdownLinkList = markdownFileList.map((item, index) => {
    let fileName = item.substr(0, item.indexOf("."))
    let linkStr = `${index+1}. [${fileName}](${item})`
    return linkStr
})
let readMarkdownContent = `# Book \r\n\r\n`
markdownLinkList.forEach(item => {
    readMarkdownContent += `${item}\r\n`
})
// 将构建的文件内容写入readme.md文件中
fs.writeFile('README.md', readMarkdownContent,  function(err) {
    if (err) {
        return console.error(err);
    }
    console.log("数据写入成功！");
 });